package com.azdebugit.trancation.test.pojo;

import com.azdebugit.trancation.test.util.MD5Util;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.Id;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import java.util.Date;

@Data
public class CompensationEntity {
    /***数据库自增id*/
    private Integer id;
    /***业务主键 根据类名，方法名，入参生成一个摘要值*/
    private String busKey;
    /***人工处理，还是自动补偿*/
    private String type;
    /***数据状态 刚入库的时候，状态为：待重试：1，重试限定次数还失败给0，重试成功后给2*/
    private String dataStatus;
    /*** 完整类名*/
    private String className;
    /*** bean名*/
    private String beanName;
    /*** 方法名*/
    private String methodName;
    /*** 方法入参类型*/
    private String reqArgsType;
    /*** 方法入参参数*/
    private String reqArgs;
    /***实际参数类型*/
    private String reqArgsTypeReal;
    /*** 重试次数*/
    private Integer retryCount;
    /*** 错误描述*/
    private String resultMsg;
    /*** 创建时间*/
    private Date gmtCreate = new Date();
    /*** 修改时间*/
    private Date gmtModified = new Date();
    /*** 是否有效*/
    private Boolean isValid = Boolean.TRUE;

    @Id
    @GeneratedValue(generator = "generator")
    @GenericGenerator(name = "generator", strategy = "native")
    @Column(name = "Id")
    public Integer getId() {
        return id;
    }

    /**
     * 业务主键 根据类名，方法名，入参生成一个摘要值
     *
     * @return 业务主键
     */
    public String createBusKey() {
        return MD5Util.msgToMD5(this.getClassName() + this.getMethodName() + this.getReqArgs());
    }

}